package com.tuo51.evaluate.service.impl;

import com.tuo51.evaluate.domain.etc.StaffSetting;
import com.tuo51.evaluate.repositories.StaffSettingRepository;
import com.tuo51.evaluate.service.StaffSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class StaffSettingServiceImpl implements StaffSettingService {

    @Autowired
    StaffSettingRepository settingRepository;

    @Override
    public StaffSetting getSetting(String staffId, String key) {
        return settingRepository.getByStaffIdAndName(staffId,key);
    }

    @Override
    public StaffSetting setSetting(String staffId, String key, String value, String ext) {

        StaffSetting setting = getSetting(staffId, key);
        if (setting == null){
            setting = new StaffSetting();
            setting.setName(key);
            setting.setStaffId(staffId);
        }

        setting.setValue(value);
        setting.setExt(ext);

        settingRepository.save(setting);

        return setting;
    }
}
